/*************************************************************************
	> File Name: oj-478.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年11月25日 星期三 13时23分29秒
 ************************************************************************/
#include <iostream>
#include <vector>
using namespace std;

struct person {
    int x, y, d;
};

int t, n;
int dir[4][2] = {
    {0, 1},//东
    {1, 0},//南
    {0, -1},//西
    {-1, 0},//北
};

void output(const vector<vector<int>> &m) {
    for (int i = 1; i < m.size() - 1; ++i) {
        for (int j = 1; j < m[0].size() - 1; ++j) {
            if (j != 1) cout << " ";
            cout << m[i][j];
        }
        cout << endl;
    }
}

int main() {
    person xm, lh;
    cin >> t;
    while (t--) {
        cin >> n;
        cin >> xm.x >> xm.y >> xm.d;
        cin >> lh.x >> lh.y >> lh.d;
        xm.x++; xm.y++; lh.x++; lh.y++;
        vector<vector<int>> mmap(n + 2, vector<int>(n + 2, 0));
        mmap[xm.x][xm.y] += 1, mmap[lh.x][lh.y] += 2;
        //output(mmap);
        //cout << "before start" << endl;
        int flag1 = 0, flag2 = 0;
        while (1) {
            if (flag1 >= 4 && flag2 >= 4) {
                cout << -1 << endl;
                break;
            }
            if (xm.x == lh.x && xm.y == lh.y) {
                cout << xm.x - 1 << " " << xm.y - 1 << endl;
                break;
            }
            while (1) {
                person txm = xm;
                txm.x += dir[xm.d][0];
                txm.y += dir[xm.d][1];
                if (flag1 == 4) break;
                if (!(mmap[txm.x][txm.y] & 1) && txm.x > 0 && txm.y > 0 && txm.x <= n && txm.y <= n) {
                    xm.x = txm.x;
                    xm.y = txm.y;
                    mmap[xm.x][xm.y] += 1;
                    flag1 = 0;
                    //output(mmap);
                    //cout << "-----------------------" << endl;
                    break;
                } else {
                    xm.d++;
                    flag1++;
                    //cout << "Flag1 = " << flag1 << endl;
                    if (xm.d == 4) xm.d = 0;
                }
            }
            while (1) {
                person tlh = lh;
                tlh.x += dir[lh.d][0];
                tlh.y += dir[lh.d][1];
                if (flag2 == 4) break;
                if (!(mmap[tlh.x][tlh.y] & 2) && tlh.x > 0 && tlh.y > 0 && tlh.x <= n && tlh.y <= n) {
                    lh.x = tlh.x;
                    lh.y = tlh.y;
                    mmap[lh.x][lh.y] += 2;
                    flag2 = 0;
                    //output(mmap);
                    //cout << "-----------------------" << endl;
                    break;
                } else {
                    lh.d--;
                    flag2++;
                    //cout << "Flag2 = " << flag2 << endl;
                    if (lh.d == -1) lh.d = 3;
                }
            }
        }
    }
    return 0;
}
